#include <bits/stdc++.h>
using namespace std;
int n, m;
int w[3501], c[3501];
int f[12880];

int main() {
    cin >> n >> m;
    for (int i = 1; i <= n; i++) {
        cin >> w[i] >> c[i];
    }

    for (int i = 1; i <= n; i++) {
        for (int j = m; j >= w[i]; j--) {
            f[j] = max(f[j], f[j - w[i]] + c[i]);
        }
    }
    cout << f[m];
    return 0;
}